package com.pluszg.nutrition.order.controller;

import com.pluszg.nutrition.api.controller.order.OrderController;
import com.pluszg.nutrition.common.resp.CommonResponse;
import com.pluszg.nutrition.model.order.Order;
import com.pluszg.nutrition.order.service.OrderService;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class OrderControllerImpl implements OrderController {

    @Autowired
    private OrderService orderService;

    @Override
    public CommonResponse<Order> submit(@RequestBody Order order) {
        return new CommonResponse<>(orderService.submit(order));
    }

    @Override
    public CommonResponse<Order> findById(@PathVariable("id") String id) {
        return new CommonResponse<>(orderService.findById(id));
    }

    @GlobalTransactional
    @Override
    public CommonResponse<Order> create(@RequestBody Order order) {
        return new CommonResponse<>(null);
    }
}
